package com.atcd.springboot2.exception;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 处理全局异常
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    //可以是多个值
    @ExceptionHandler({ArithmeticException.class,NullPointerException.class})
    public  String handlerException(Exception e){
        log.error("异常是:{}",e);

        //错误返回一个modelAndView 视图
        return "/error/4xx";
    }
}
